<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>初始化 state</title>
</head>
<body>
    <div id="root"> </div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        class App extends React.Component{
            //方式一 完整写法
            // //1. 声明构造方法
            // constructor(){
            //     //2. 调用 super 函数
            //     super();
            //     //3. this 创建 state 属性
            //     this.state = {
            //         isNight: false
            //     }
            // }

            //方式二 简便写法
            state = {
                isNight: false
            }

            render(){
                //解构赋值
                let {isNight} = this.state;
                return <h2>至尊宝, 我是{isNight ? '青霞' : '紫霞'}</h2>
            }
        }

        ReactDOM.render(<App />, document.querySelector("#root"));

    </script>
</body>
</html>